--Use CodeCamp;
GO

--**** Send results to text

--*****************************************************
--** Run this query to text output
--** suggest setting Output Format to "tab delimited"
--** and "Maximum number of characters" to 4096
--** in Query Options for Text
--*****************************************************

--Query to get most recent log entry with exception

Declare @LogEntryID int

Select
	Top 1 @LogEntryID = LogEntryID
From dbo.aspnetRgs_log4net
Where Exception is not null and DATALENGTH(Exception) > 0
Order by LogTimeLocal Desc, LogEntryID Desc
	
--Declare @LogEntryID int Set @LogEntryID = 586


Select
	LogEntryID
	,Convert(varchar,LogTimeLocal,21) [Log Time]
	,MachineName
	,ThreadId
	,UserName
	,Url
	,'
-----
	' [-]
	,[Message]
	,'
-----
	' '-'
	,Exception
From dbo.aspnetRgs_log4net With (NOLOCK)
Where LogEntryID = @LogEntryID
Order by LogEntryID Desc

